package hn.cch.custom;

import hn.cch.util.JsonUtil;
import org.apache.kafka.common.header.Headers;
import org.apache.kafka.common.serialization.Serializer;

import java.nio.charset.StandardCharsets;
import java.util.Map;

public class CustomSerializer implements Serializer<CustomObject> {

    @Override
    public void configure(Map<String, ?> configs, boolean isKey) {

    }

    @Override
    public byte[] serialize(String s, CustomObject customObject) {
        // 使用json格式序列化
        return JsonUtil.toStringJackson(customObject).getBytes(StandardCharsets.UTF_8);
    }

    @Override
    public byte[] serialize(String topic, Headers headers, CustomObject data) {
        return serialize(topic, data);
    }

    @Override
    public void close() {

    }
}
